<?php 
	require_once("models/config.php");
	require_once("ui.php");
	require_once("debugging.report/report.template.php");

	if(!isUserLoggedIn()) {
		header ("location: login.php");
		die();
	}

	global $loggedInUser;
	$isAdmin = $loggedInUser->isAdministrator();
	if ($isAdmin) {
		header ("location: users.php");
		die();		
	}
?>

<?php 

$reportTemplate = new ToolingReportTemplate();

//Forms posted
if(!empty($_POST)) {
	global $reportPostErrors;
	$reportPostErrors = $reportTemplate->processFormPost($loggedInUser);
}

function printHeader() {
	global $reportPostErrors;
	
	if (isset($reportPostErrors)) {
		if (count($reportPostErrors) == 0) {
			echo '<meta HTTP-EQUIV="REFRESH" content="0; url=' . $_SERVER['PHP_SELF'] . '?success=true">';
			return;		
		}
	}
	
	echo '<script src="./js/prototype.js"></script>';
	echo '<script src="./js/debugging.report.form.js"></script>';
	
	global $reportTemplate;
	$reportTemplate->generateJs();	
}

?>
		
<?php printPageHead("initPage()", "printHeader"); ?>

	<?php printNavigationBar('index', NAVIGATION_ITEM_FILE_BUG) ?>		
		
		<div id="content" class="container_16 clearfix">
			<form id="reportForm" name="reportForm" action="<?php echo $_SERVER['PHP_SELF'] . "#result-anchor"; ?>" method="post">
					
				<div id="reportFormNavigationArea">
					<div id="reportFormNavigation">
						<div id="reportNavigationList">
							<ul>
								<!-- 
								<li><span id="general" class="active" onclick='changeMenu("general")'><a href="#">General</a></span></li>
								<li><span id="detection" onclick='changeMenu("detection")'><a href="#">Detection</a></span></li>
								<li><span id="root_cause" onclick='changeMenu("root_cause")'><a href="#">Root Cause</a></span></li>
								<li><span id="used_methods" onclick='changeMenu("used_methods")'><a href="#">Used Methods</a></span></li>
								<li><span id="used_tools" onclick='changeMenu("used_tools")'><a href="#">Used Tools</a></span></li>
								<li><span id="optional_menu" onclick='changeMenu("optional_menu")'><a href="#">Optional</a></span></li>
								 -->
								<li><span id="general" class="active" onclick='changeMenu("general")'><a href="#">General</a></span></li>
								<li><span id="used_tools" onclick='changeMenu("used_tools")'><a href="#">Used Tools</a></span></li>
								<li><span id="optional_menu" onclick='changeMenu("optional_menu")'><a href="#">Optional</a></span></li>
							</ul>
						</div>
					</div>
				</div>

				<?php global $reportTemplate; $reportTemplate->printTabs(); ?>

				<div id="formButtonsDiv">
					<div id="reportNavButton" class="formButton" onclick="moveMenu(false);"><a href="#">&#60;&#60; Previous tab</a></div>
					<div id="reportNavButton" class="formButton" onclick="moveMenu(true);"><a href="#">Next tab &#62;&#62;</a></div>
					<div id="reportNavButton" class="formButton"><input type="submit" value="Submit" class="submit" /></div>
				</div>				
			</form>

			<div id="reportSubmissionResultDiv">
				<a id="result-anchor"></a>
			<?php 
				if (isset($reportPostErrors)) {
					if (count($reportPostErrors) > 0) {
						echo '<span id="reportSubmissionFailureTitle">Report not submitted</span><br>';
						
						echo '<ul id="reportSubmissionResultlist">';
						foreach ($reportPostErrors as $i => $error) {
							echo "<li>$error</li>" . PHP_EOL;
						}
						
						echo '</ul>';
					}
				}
				
				if (isset($_GET['success'])) {
					if ($_GET['success'] == "true") {
						echo '<span id="reportSubmissionSuccessTitle">Report submitted</span><br>';
					}
				}
			?>
			</div>
		</div>
 
<?php printPageFoot(); ?>
